var Utils = {
    /**
     * 解析url中字符
     * @param  {String} url  [url]
     * @param  {String} name [name]
     * @return {[type]}      [description]
     */
    parseQueryString: function(url) {
        if (!this.isUrl(url)) {
            return {};
        }
        var nvpair = {};
        var qs = url.replace(/.*\?/, '');
        var pairs = qs.split('&');
        pairs.forEach(function(v,i,arr){
            var pair = v.split('=');
            nvpair[pair[0]] = pair[1];        
        });
        return nvpair;
    },

    isUrl : function(url) {
        return /^(http|https):\/\/([\w-]+(:[\w-]+)?@)?[\w-]+(\.[\w-]+)+(:[\d]+)?([#\/\?][^\s<>;"\']*)?$/.test(url);
    },

   enumerables : [//'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
                       'valueOf', 'toLocaleString', 'toString', 'constructor'],
    apply : function(object, config, defaults) {
        var enumerables = this.enumerables;
        if (defaults) {
            this.apply(object, defaults);
        }


        if (object && config && typeof config === 'object') {
            var i, j, k;

            for (i in config) {
                object[i] = config[i];
            }

            if (enumerables) {
                for (j = enumerables.length; j--;) {
                    k = enumerables[j];
                    if (config.hasOwnProperty(k)) {
                        object[k] = config[k];
                    }
                }
            }
        }

        return object;
    },

    getJSON : function(config) {
        config = this.apply({
            url : '',
            method :'get',
            success : function(){},
            failure : function(){}
        },config || {});
        var xhr = new XMLHttpRequest();
        xhr.open(config.method,config.url, true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                if (typeof config.success == 'function') {
                    config.success.call(this,xhr)
                }  
          }
        }
        xhr.send();
    }
};
